import {createStore,combineReducers,applyMiddleware}  from 'redux'
// 中间件
// import thunk from 'redux-thunk'
import createSagaMiddleware from 'redux-saga'
import {helloSaga} from './sagas/hello';
import {watchCountSaga} from './sagas/count';


//合并reducer文件中所有分支 
import reducerCounter from './reducers/reducerCounter'
import reducerStudent from './reducers/reducerStudent'
import reducerTask from './reducers/reducerTask'

const rootReducer = combineReducers({
    reducerCounter,
    reducerStudent,
    reducerTask
})

const sagaMiddleware = createSagaMiddleware()

// Before running a Saga, you must mount the Saga middleware on the Store using applyMiddleware
//run 启动一个saga任务
// sagaMiddleware.run(helloSaga)

// 03 定义store ； combineReducers 合并reducers；applyMiddleware 构建中间件 形成中间件链；
const store = createStore(rootReducer,applyMiddleware(sagaMiddleware))

//run 启动一个saga任务
// sagaMiddleware.run(helloSaga)

//监听saga : 相当于启动一个服务进程
sagaMiddleware.run(watchCountSaga)

export default store

